#ifndef _SOCKET_H_
#define _SOCKET_H_

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x501
#endif

#pragma once
#include "../log/Log.h"
#include "ByteBuffer.h"
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iostream>
#include <sstream>
#include <string>
#include "NetworkException.h"
#include "../threads/Mutex.h"

class Socket
{
public:
	int doSend(const char* sendbuf, size_t bufSize);
	int doReceive(char* recvbuf, int recvbuflen);

	void doSendComplete(const ByteBuffer* sendbuf);
	void doReceiveComplete(ByteBuffer* recvbuf);
	
	void doClose();
	void doShutdown();
	std::string toString();
protected:
	Socket();
	virtual ~Socket();
	SOCKET socketConnection;
	struct addrinfo* addInfoResult;
	static const int WSA_VERSION = 2;
	static const int WSA_REVISION = 2;
private:
	static int socketCount;
	Mutex socketCountMutex;
};

#endif
